package com.borrow.jiemihua.base;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
 * Created by litao
 * 注释:fragment的基类
 * Created by 2017/12/7 0022.
 */

public   abstract  class Base2Fragment extends Fragment implements View.OnClickListener {
    public View view;
    public Activity mActivity;




    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mActivity = getActivity();
        initData();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onStart() {
        super.onStart();
        // 告诉FragmentActivity，当前Fragment在栈顶
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        displayMetrics.scaledDensity = displayMetrics.density;
    }



    public View getRootView() {
        return view;
    }


    /**
     * 初始化数据
     */
    public abstract void initData();

    /**
     * 跳转到其他页面
     */
    public void jumpActivity(Class<? extends Activity> activity, Bundle bundle) {

        Intent intent = new Intent();
        intent.setClass(mActivity, activity);
        if (bundle != null) {
            intent.putExtras(bundle);
        }

        startActivity(intent);

    }

    /**
     * 通过requestCode跳转到指定的页面
     *
     * @param activity
     * @param bundle
     * @param requestCode
     */
    public void jumpActivityForResult(Class<? extends Activity> activity, Bundle bundle, int requestCode) {
        Intent intent = new Intent();
        intent.setClass(mActivity, activity);
        if (bundle != null) {
            intent.putExtras(bundle);
        }

        startActivityForResult(intent, requestCode);
    }


    @Override
    public void onClick(View v) {

    }
}